package zq.cn.dao;

import android.database.Cursor;

import java.util.Map;

import util.Globals;

/**
 * Created by ZQ on 2016/4/21.
 */
public class PageDao {

    public static void insertPageInfo(Map<String, Object> map) {
        String sql = "insert into page_tab(txtId, pageNum, content) " +
                " values(?, ?, ?)";
        Globals.db.getWritableDatabase().execSQL(sql, new Object[]{
                map.get("txtId"),map.get("pageNum"), map.get("content")});
    }

    public static String getTxtContent(int txtId, int pageNum) {
        String sql = "select content from page_tab where txtId=? and pageNum=?";
        Cursor c = Globals.db.getReadableDatabase().rawQuery(sql, new String[]{txtId+"", pageNum+""});
        c.moveToFirst();
        String content = c.getString(0);
        c.close();
        return content;
    }

    public static int getCountByTxtId(int txtId) {
        String sql = " select count(*) from page_tab where txtId=? ";
        Cursor c = Globals.db.getReadableDatabase().rawQuery(sql, new String[]{txtId+""});
        c.moveToFirst();
        int count = c.getInt(0);
        c.close();
        return count;
    }

}
